#include<bits/stdc++.h>
using namespace std;
struct student{
	string id;
	int site1,site2;
};
int cmp(student a,student b){
	return a.site1<b.site1;
}
int main(){
	int n,m,s1;
	cin>>n;
	student stu[n];
	for(int i=0;i<n;i++)
		cin>>stu[i].id>>stu[i].site1>>stu[i].site2;
	sort(stu,stu+n,cmp);
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>s1;
		cout<<stu[s1-1].id<<" "<<stu[s1-1].site2<<endl;
	}
	return 0;
} 
